public without sharing class AT_Debug_Log_Trigger_Handler
{
    private boolean m_isExecuting = false; 
    private integer BatchSize = 0;
         
    public AT_Debug_Log_Trigger_Handler(boolean isExecuting, integer size)
    {
        m_isExecuting = isExecuting;
        BatchSize = size;
    }
    
	public void OnAfterUpdate(List<AT_Debug_Log__c> updatedItems, Map<Id, AT_Debug_Log__c> newItemsMap, Map<Id, AT_Debug_Log__c> oldItemsMap)
	{
		List<AT_Debug_Log__c> list2Upd = new List<AT_Debug_Log__c>();
		Set<ID> setDLIDs = new Set<ID>();
		Map<ID,ID> mapCurDL2PrevDL = new Map<ID,ID>();
		for(AT_Debug_Log__c item:updatedItems){ setDLIDs.add(item.id);}
		
		for(AT_Debug_Log__c item:[select ID,Log_for_Resend__c from AT_Debug_Log__c where Log_for_Resend__c in :setDLIDs])
		{
			mapCurDL2PrevDL.put(item.Log_for_Resend__c,item.ID);
		}
		
    	for(AT_Debug_Log__c item:updatedItems)
    	{
    		if(item.Status__c == 'Success' && mapCurDL2PrevDL.containsKey(item.ID) && newItemsMap.get(item.id).Status__c!=oldItemsMap.get(item.id).Status__c)
    		{
    			
    			AT_Debug_Log__c updItem = new AT_Debug_Log__c(ID=mapCurDL2PrevDL.get(item.ID), Status__c='Fixed');
    			list2Upd.add(updItem);
    		}
    	}
    	if(list2Upd.size()>0) update list2Upd;
	}
	public void OnAfterInsert(List<AT_Debug_Log__c> newItems)
	{ 
    	List<AT_Debug_Log__c> list2Upd = new List<AT_Debug_Log__c>();
		Set<ID> setDLIDs = new Set<ID>();
		Map<ID,ID> mapCurDL2PrevDL = new Map<ID,ID>();
		for(AT_Debug_Log__c item:newItems){ setDLIDs.add(item.id);}
		
		for(AT_Debug_Log__c item:[select ID,Log_for_Resend__c from AT_Debug_Log__c where Log_for_Resend__c in :setDLIDs])
		{
			mapCurDL2PrevDL.put(item.Log_for_Resend__c,item.ID);
		}

    	for(AT_Debug_Log__c item:newItems)
    	{
    		if(item.Status__c == 'Success' && mapCurDL2PrevDL.containsKey(item.ID) && item.Log_for_Resend__c!=null)
    		{
    			AT_Debug_Log__c updItem = new AT_Debug_Log__c(ID=mapCurDL2PrevDL.get(item.ID), Status__c='Fixed');
    			list2Upd.add(updItem);
    		}
    	}
    	if(list2Upd.size()>0) update list2Upd;
	}
}